//
//  MoeBaseViewController.m
//  01_kakin
//
//  Created by jon due on 12/03/19.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MoeBaseViewController.h"

/* rext */
#define Rect_dataLabel    CGRectMake(50, 350, 160, 40)
#define Rect_TimeLabel    CGRectMake(50, 390, 160, 40)  
#define Rect_weekLabel    CGRectMake(150, 390, 160, 40)

#define Rect_MainBGImg    CGRectMake(0, 0, 320, 480)
#define Rect_parsonImg    CGRectMake(0, 0, 320, 480)


@implementation MoeBaseViewController

@synthesize dateLabel = _dateLabel;
@synthesize timeLabel = _timeLabel;
@synthesize weekLabel = _weekLabel;

@synthesize mainBGImg = _mainBGImg;
@synthesize parsonImg = _parsonImg;

@synthesize timer = _timer;
@synthesize weekAry = _weekAry;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    /*== 曜日配列 ==*/
    self.weekAry = [[ NSArray alloc ]initWithObjects:@"Mon",@"Tue",@"Wed",@"Thu",@"Fri",@"Sat",@"Sun", nil];
    
    /*== UI ==*/
    self.dateLabel = [[ UILabel alloc ]initWithFrame:Rect_dataLabel];
    self.timeLabel = [[ UILabel alloc ]initWithFrame:Rect_TimeLabel];
    self.weekLabel = [[ UILabel alloc ]initWithFrame:Rect_weekLabel];
    
    self.dateLabel.font = [ UIFont fontWithName:fontPocket size:40 ];
    self.timeLabel.font = [ UIFont fontWithName:fontPocket size:40 ];
    self.weekLabel.font = [ UIFont fontWithName:fontPocket size:30 ];
    
    UIColor *bgColor = [ UIColor clearColor ];
    self.dateLabel.backgroundColor = bgColor;
    self.timeLabel.backgroundColor = bgColor;
    self.weekLabel.backgroundColor = bgColor;
    
    
    self.mainBGImg = [[ UIImageView alloc ]initWithFrame:Rect_MainBGImg];
    self.parsonImg = [[ UIImageView alloc ]initWithFrame:Rect_parsonImg];
    
    self.mainBGImg.image = [ UIImage imageNamed:IMG_MainBG ];
    self.parsonImg.image = [ UIImage imageNamed:IMG_Pserson ];
    
    // add View
    [ self.view addSubview:self.mainBGImg ];
    [ self.view addSubview:self.parsonImg ];
    [ self.view addSubview:self.dateLabel ];
    [ self.view addSubview:self.timeLabel ];
    [ self.view addSubview:self.weekLabel ];
    
    
    /*== 初期値セット ==*/
    [ self setNowTime:nil ];
    
    /*== タイマーをセット ==*/
    self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(setNowTime:) userInfo:nil repeats:YES];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    
}

-(void)dealloc{
    [ _dateLabel release ];
    [ _timeLabel release ];
    [ _weekLabel release ];
    
    [ _mainBGImg release ];
    [ _parsonImg release ];
    
    [_timer invalidate];
	_timer = nil;
    [ _timer release ];
    [ _weekAry release ];
    
    [ super dealloc ];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

/* ============================================================================== */
#pragma mark - 日付をセット
/* ============================================================================== */

-(void)setNowTime:(NSTimer*)t{
    
    NSArray *ary = [ SADate getDate ];
    
    self.dateLabel.text = [ ary objectAtIndex:0 ];
    self.timeLabel.text = [ ary objectAtIndex:1 ];
    
    self.weekLabel.text = [ NSString stringWithFormat:@"(%@)",[self.weekAry objectAtIndex:[ SADate getWeek ]] ];
    
}

/* ============================================================================== */
#pragma mark - 
/* ============================================================================== */



@end
